var mtagIndex = 0;
loadGoodsBykey = (index) => {
	mtagIndex = index;
	let mlist = getAllGoods();
	let goodsHtml = `<div class="goods_container">`;
	if (mlist && mlist.length > 0) {
		for (var i = 0; i < mlist.length; i++) {
			let item = mlist[i];
			
			let spuTagList = item.spuTagList;
			let spuTagHtml = ``;
			if (spuTagList && spuTagList.length > 0) {
				spuTagList.forEach(e => {
					spuTagHtml += `<label class="label">${e.title}</label>`
				})
			}
			
			goodsHtml += `<div class="goods_item" onclick="onGetItem('${item.storeId}')">
							<img src="${item.primaryImage}" class="goods_item_img"/>
							<div class="goods_content">
								<div class="title">${item.title}</div>
								<div class="goods_tag">${spuTagHtml}</div>
								<div class="goods_item_option">
									<div class="spec_for_price">
										<span class="symbol">¥</span>${getPrice(item.minSalePrice)}
									</div>
									<div class="goods-card__origin-price">
										<span class="symbol">¥</span>${getPrice(item.maxLinePrice)}
									</div>
									<img src="img/ic_add_card.png" class="goods_img_car" onclick="onAddCard('${item.storeId}')"/>
								</div>
							</div>
						</div>`;
		}
	}
	goodsHtml += `</div>`;
	return goodsHtml;
}

getPrice = (price) => {
	if (price) {
		let newPrice = parseFloat(price) / 100;
		return newPrice
	}
	return '0'
}

onGetItem = (id) => {
	navigateTo(`page/goods/detail.html`)
}

onAddCard = (id) => {
	event.stopImmediatePropagation(); //阻止事件分发
	let subLoading = layer.open({
		type: 2,
		shadeClose: false,
		content: '正在操作...'
	});
	setTimeout(() => {
		layer.close(subLoading);
		showToast('操作成功！');
		loadGoodsBykey(mtagIndex);
	}, 1000)
}
